package chixing.day12.homwork.work9;

import java.util.ArrayList;
import java.util.Iterator;

public class Library {
    private static Library library = new Library();
    private   ArrayList<Book> bookArrayList ;

    private Library() {
        bookArrayList=new ArrayList<>();
    }

    public static Library getInstance(){
        return library;
    }


    //添加图书
    public void addBook(Book book){
        bookArrayList.add(book);

    }
    //删除图书
    public void removeBook(String bookName){
        Iterator<Book> iterator = bookArrayList.iterator();
        while (iterator.hasNext()){
            Book book = iterator.next();
            if (book.getBookName().equals(bookName))
                iterator.remove();
        }
    }
    //查找图书
    public void findtBook(String keyword){
        for (Book b:bookArrayList) {
            if (b.getBookName().equals(keyword) || b.getBookAuthor().equals(keyword))
                System.out.println(b);
        }
    }
    //显示所有图书列表
    public void display(){
        for (Book b:bookArrayList) {
            System.out.println(b);
        }
    }
}
